
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <base href="/">
  <meta charset="utf-8">
  <title>发表问题 编辑问题 公用</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
  <link rel="stylesheet" href="res/layui/css/layui.css">
  <link rel="stylesheet" href="res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
  <div class="layui-container">
    <a class="fly-logo" href="/">
      <img th:src="${index[0].blogLogo}" alt="layui" width="200" height="40">
    </a>
  </div>
</div>

<div class="layui-container fly-marginTop">
  <div class="fly-panel" pad20 style="padding-top: 5px;">
    <!--<div class="fly-none">没有权限</div>-->
    <div class="layui-form layui-form-pane">
      <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title">
          <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
        </ul>
        <div class=" layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <div class="layui-form">
              <div class="layui-row layui-col-space15 layui-form-item">
                <div class="layui-col-md3">
                  <label class="layui-form-label">文章分类</label>
                  <div class="layui-input-block">
                    <select name="modules" lay-verify="required" lay-search="" id="blogText">
                      <option th:each="blogclass:${blogClassUser}" th:value="${blogclass.classifyId}" th:text="${blogclass.classifyName}"></option>
                    </select>
                  </div>
                </div>
                <div class="layui-col-md9">
                  <label for="L_title" class="layui-form-label">标题</label>
                  <div class="layui-input-block">
                    <input type="text" id="L_title" name="title" lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                    <!-- <input type="hidden" name="id" value="{{d.edit.id}}"> -->
                  </div>
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">
                  <textarea class="layui-textarea" id="LAY_demo1" name="LAY_demo1" style="display: none"></textarea>
                </div>
              </div>

              <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="layuiadmin-app-form-submit">立即发布</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<footer th:replace="footer::header-fragment"></footer>

<script src="res/layui/layui.js"></script>
<script>
  layui.config({
    base: 'layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form','layedit','element'], function(){
  var $ = layui.$
          ,form = layui.form
          ,layedit = layui.layedit
          ,$ = layui.jquery,
          element = layui.element;
  form.render();
  //上传图片,必须放在 创建一个编辑器前面
  layedit.set({
    uploadImage: {
      url: 'admin/uploadPicture' //接口url
      ,type: 'post' //默认post
    }
  });
  //构建一个默认的编辑器
  var index2 = layedit.build('LAY_demo1');

  //编辑器外部操作
  var active = {
    content: function(){
      alert(layedit.getContent(index)); //获取编辑器内容
    }
    ,text: function(){
      alert(layedit.getText(index)); //获取编辑器纯文本内容
    }
    ,selection: function(){
      alert(layedit.getSelection(index));
    }
  };

  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  //监听提交
  form.on('submit(layuiadmin-app-form-submit)', function(data){
    var field = data.field; //获取提交的字段
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    var sta = field.status==1?1:0;  //获取状态
    var content = layedit.getContent(index2);
    var blogText = $("#blogText").find("option:selected").text()
    //提交 Ajax 成功后，关闭当前弹层并重载表格
    $.post('admin/addUserBlog',{
      "title":field.title,
      "modules":field.modules,
      "status":sta,
      "content":content,
      "blogText":blogText
    },function (res){
      if (res.success){
        if (sta==1){
          layer.msg('发布文章成功', {
            offset: '15px'
            ,icon: 1
            ,time: 1000
          });
        }else {
          layer.msg('请等待审核', {
            offset: '15px'
            ,icon: 1
            ,time: 1000
          });
        }

        $("input[name='title']").val('');
        layui.layedit.clearContent(index)
      }else {
        layer.msg('发布失败', {
          offset: '15px'
          ,icon: 1
          ,time: 1000
        });
      }
    },'json');
  });
});
</script>

</body>
</html>